const $api = require('../../utils/api.js').API;
Page({
    data: {
        current: '0',
        order_list: [],
        card_bg: ['express', 'cart', 'other'],
        order_bg_base: ''
    },

    onShow() {
        console.log('home onshow')
        this.loadList()
        this.loadImg()
    },

    // 加载订单列表
    loadList() {
        $api.getOrderList()
            .then(res => {
                this.setData({
                    order_list: res.data.data
                })
            })
            .catch(err => console.log(err))
    },

    // 加载订单背景图
    loadImg() {
        $api.loadImg()
            .then(res => {
                console.log(res.data.data)
                this.setData({
                    order_bg_base: res.data.data
                })
            })
            .catch(err => console.log(err))
    },

    // 更换导航标签
    handleChange({ detail }) {
        this.setData({
            current: detail.key
        });
    },

    // 去往订单详情页
    toDetail(e) {
        console.log(e.currentTarget.dataset)
        wx.setStorage({
            key: 'orderDetail',
            data: e.currentTarget.dataset,
            success: (result) => {
                wx.navigateTo({
                    url: '/pages/orderDetail/orderDetail',
                });
            },
        });
    },

    // 去往发布订单编辑信息页
    addOrder() {
        wx.navigateTo({
            url: '/pages/publish/publish',
        });
    }
})
